# -*- coding:utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import api, fields, models, _


class AccountChartTemplate(models.Model):
    _inherit = "account.chart.template"

    @api.multi
    def _prepare_all_journals(self, acc_template_ref, company, journals_dict=None):
        """Create the tax_cash_basis_journal_id"""
        res = super(AccountChartTemplate, self)._prepare_all_journals(
            acc_template_ref, company, journals_dict=journals_dict)
        if not self == self.env.ref('l10n_cn_smb_2019.l10n_chart_china_small_business'):
            return res
        account = acc_template_ref.get(self.env.ref('l10n_cn_smb_2019.l10n_cn_2211').id)
        res.append({
            'type': 'general',
            'name': _('薪资账簿'),
            'code': 'SLRY',
            'company_id': company.id,
            'default_credit_account_id': account,
            'default_debit_account_id': account,
            'show_on_dashboard': True,
        })
        return res



class HrContract(models.Model):
    _inherit = 'hr.contract'


    @api.model
    def _get_default_journal(self):
        return self.env.ref('l10n_cn_hr_payroll_account.salary_journal', False)

    journal_id = fields.Many2one(
        'account.journal', 'Salary Journal', default = _get_default_journal )

